/*
 * @Author: mikey.zhaopeng 
 * @Date: 2018-12-26 20:43:45 
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2018-12-26 23:47:15
 */
import 'package:flutter/material.dart';
import '../modles/tv_schedule.dart';
import '../widgets/tag.dart' show Tag;

class TodaysBoardcast extends StatelessWidget{
  final List<TVSchedule> schedules;
  
  const TodaysBoardcast({Key key,this.schedules}):super(key:key);

  @override
  Widget build(BuildContext context){
    return Container(
      height: 150.0,
      child: OverflowBox(
        child: GridView.builder(
        shrinkWrap: false,
        scrollDirection: Axis.horizontal,
        itemCount: schedules.length,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          childAspectRatio: 1.2,
          crossAxisCount: 1,
          crossAxisSpacing: 5.0,
          mainAxisSpacing: 8.0,
        ),
        itemBuilder: (context,index){
          final item = schedules[index];
          return GestureDetector(
            onTap: (){
              //to do 跳转到视频页面
              print(index);
            },
            child: Card(
              margin: const EdgeInsets.all(0.0),
              child: GridTile(
                child: Hero(
                  tag: item.poster,
                  child: FadeInImage(
                    fit: BoxFit.cover,
                    image: NetworkImage(item.poster),
                    placeholder: AssetImage('assets/images/placeholder.png'),
                  ),
                ),
                header: GridTileBar(
                  leading: item.statusCn.isNotEmpty
                    ?Tag(
                      text: item.statusCn,
                      color: Colors.white,
                      backgroundColor: Theme.of(context).primaryColorDark.withAlpha(200),
                    ):Container(),
                ),
                footer: Container(
                  height: 40.0,
                  child: GridTileBar(
                    title: Text(
                      item.cnname,
                      style: TextStyle(fontSize: 12.0),
                    ),
                    backgroundColor: Colors.black.withAlpha(120),
                    subtitle: Text(
                      "S${item.season.padLeft(2,'0')}E${item.episode.padLeft(2,'0')}",
                      style: TextStyle(color: Colors.white,fontSize: 12.0),
                    ),
                  ),
                ),
              ),
            ),
          );
        },
      ),
      ),
    );
  }
}